package com.ima.web.common.controllers;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


import com.ima.web.beans.db.Users;
import com.ima.web.service.UserService;

@Controller
public class ProfileController {
	
	private UserService userService;
	private Logger log;
	
	public ProfileController(){
		log = Logger.getLogger(this.getClass());
	}
	
	@Autowired
	public void setDependencies(UserService userService){
		this.userService = userService;
	}
	
	
//	
//	@RequestMapping("/p")
//	public String viewProfile2(ModelMap model){
//		model.put("msg", "test single");
//		
//		return "public/profile";us
//	}
	
	@RequestMapping(value="/profile/{id}",method=RequestMethod.GET)
	public String viewProfile(@PathVariable("id") Integer userId,ModelMap model){
		
		Users u = userService.getUserData(userId);
		
		if(u==null)
			log.debug("\n\nPROFILE IS NULL\n\n");
		
		//System.out.println("viewProfile: "+u.getPenName());
		
		model.put("user", u);
		
		return "public/profile";
	}
	
	@RequestMapping("profiletest")
	public String viewProfile1(ModelMap model){
		model.put("msg", "Well profile test well well well");
		
		return "public/profile";
	}
}
